// services/assetPaths.js
import { ipcMain } from 'electron';
import {
  getAllAssetPaths,
  addAssetPath,
  updateAssetPath,
  deleteAssetPath,
  toggleAssetPathStatus,
  getAssetPathById,
  getAssetPathByKey,
  getAllEnabledAssetPaths,
  getEffectiveAssetPaths, getBaseUrl
} from '../dao/assetPaths.js'

const MODEL_NAME = 'assetPath';

export function init() {
  // 获取所有资源路径
  ipcMain.handle(`${MODEL_NAME}/getAll`, () => {
    return getAllAssetPaths();
  });

  // 添加新资源路径
  ipcMain.handle(`${MODEL_NAME}/add`, (event, pathKey, pathValue, description, enabled) => {
    return addAssetPath(pathKey, pathValue, description, enabled);
  });

  // 更新资源路径
  ipcMain.handle(`${MODEL_NAME}/update`, (event, id, data) => {
    return updateAssetPath(id, data);
  });

  // 删除资源路径
  ipcMain.handle(`${MODEL_NAME}/delete`, (event, id) => {
    return deleteAssetPath(id);
  });

  // 启用/禁用资源路径
  ipcMain.handle(`${MODEL_NAME}/toggle`, (event, id, enabled) => {
    return toggleAssetPathStatus(id, enabled);
  });

  // 根据ID获取单个资源路径
  ipcMain.handle(`${MODEL_NAME}/getById`, (event, id) => {
    return getAssetPathById(id);
  });

  // 根据键获取单个资源路径
  ipcMain.handle(`${MODEL_NAME}/getByKey`, (event, pathKey) => {
    return getAssetPathByKey(pathKey);
  });

  // 获取所有启用的资源路径
  ipcMain.handle(`${MODEL_NAME}/getAllEnabled`, () => {
    return getAllEnabledAssetPaths();
  });

  // 获取当前生效的资源路径配置
  ipcMain.handle(`${MODEL_NAME}/getEffective`, () => {
    return getEffectiveAssetPaths();
  });

  // 获取baseUrl
  ipcMain.handle(`${MODEL_NAME}/getBaseUrl`, () => {
    return getBaseUrl();
  });
}
